﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Timer = System.Windows.Forms.Timer;

namespace DetectScars.Menus
{
    public partial class AutoCloseMessageBox: Form
    {

        private Label messageLabel;
        private Timer timer;

        public AutoCloseMessageBox(string message, int duration)
        {
            // 设置窗体样式
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Width = 300;
            this.Height = 150;

            // 添加消息标签
            messageLabel = new Label
            {
                Text = message,
                Dock = DockStyle.Fill,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter,
                AutoSize = false
            };
            this.Controls.Add(messageLabel);

            // 设置定时器
            timer = new Timer { Interval = duration };
            timer.Tick += (sender, args) => this.Close();
            timer.Start();
        }
    }
}
